import java.util.HashSet;

public class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    public void fun() {
        int n = val;
        ListNode listNode = new ListNode();
    }
 }
class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        ListNode cur = head.next;
        head.next = null;
        ListNode ret = head;
        HashSet<Integer> set = new HashSet<>();
        set.add(head.val);
        while(cur != null) {
            if(!set.contains(cur.val)) {
                head.next = cur;
                head = head.next;
            }
            cur = cur.next;
        }
        return ret;
    }
}

